package liczba;
class LiczbaException extends Exception {
	LiczbaException() {super();}
	LiczbaException(String s) {super(s);}
}
public class Liczba  {

	int numb;
	Liczba(int n) {this.numb = n;}
	void setNumb(int n) {this.numb = n;}
	String toBase(int p) throws LiczbaException {
		if(p<2 || p>18) throw new LiczbaException("Niepoprawna podstawa systemu wyjściowego");
		if(this.numb < 0) throw new LiczbaException("Liczba nie jest liczbą naturalną");
		
		int currentRemainder; char currentChar; String solution = "";
		while (numb > 3) {
			currentRemainder = numb % p;
		    if(currentRemainder < 10) currentChar = (char) (currentRemainder + 48);
		    else currentChar = (char) (currentRemainder + 87);
		    solution = currentChar + solution;
		    numb = numb / p;
		}
		return solution;
	}
}
